package simpledb.GUI;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Driver;
import java.util.ArrayList;
import java.util.List;

import simpledb.remote.SimpleDriver;
import sun.misc.Regexp;

import com.trolltech.qt.core.QFile;
import com.trolltech.qt.gui.*;

public class TreeWindow extends QWidget {

	public TreeWindow() {
		QTreeWidget treeWidget = new QTreeWidget(this);
		treeWidget.setAnimated(true);
		treeWidget.header().hide();
		List data = new ArrayList<Integer>();
	    try {
	        BufferedReader input =  new BufferedReader(new FileReader("tree"));
	        try {
	          String line = null;
	          while ((line = input.readLine()) != null)
	          {
	        	  data.add(line);
	          }
	        }
	        finally {
	          input.close();
	        }
	      }
	      catch (IOException ex){
	        ex.printStackTrace();
	      }

	    String[] tableNames = data.get(0).toString().replaceAll("[\\[\\],]", "").split(" ");
	    String table1String = tableNames[0];
	    String table2String = tableNames[1];
	    String predicates = data.get(1).toString();
	    String projectionList = data.get(2).toString();


		QTreeWidgetItem projection = new QTreeWidgetItem();
		QIcon pi = new QIcon("/Something/pi");
		projection.setIcon(0, pi);
		projection.setText(0, projectionList);
		QTreeWidgetItem selection = new QTreeWidgetItem();
		QTreeWidgetItem product = new QTreeWidgetItem();
		QTreeWidgetItem table1 = new QTreeWidgetItem();
		QTreeWidgetItem table2 = new QTreeWidgetItem();
		selection.setText(0, predicates);
		QIcon x = new QIcon("/Something/X.png");
		product.setIcon(0, x);
		QIcon sigma = new QIcon("/Something/Sigma.png");
		selection.setIcon(0, sigma);
		table1.setText(0, table1String);
		table2.setText(0, table2String);
		treeWidget.addTopLevelItem(projection);
		projection.addChild(selection);
		selection.addChild(product);
		product.addChild(table1);
		product.addChild(table2);
		treeWidget.expandAll();
		
		QVBoxLayout layout = new QVBoxLayout();
		layout.addWidget(treeWidget);
		setLayout(layout);

	}

//	public static void main(String[] args) {
//		QApplication.initialize(args);
//
//		
////		TreeWindow win = new TreeWindow("treeFile");
////		win.show();
//		QApplication.exec();
//	}

}
